/**
 * 
 */
package co.droidforum.foodx.exception.handlers;

import co.droidforum.foodx.R;
import co.droidforum.foodx.application.AplicationContext;
import co.droidforum.foodx.utils.DroidAlertDialog;
import co.droidforum.foodx.utils.DroidDialogAction;
import co.droidforum.foodx.workers.BusinessWorker;
import co.droidforum.foodx.workers.ProcessExceptionHandler;
import co.droidforum.foodx.ws.RemoteConnectionServiceException;

/**
 * @author andres.alzate
 *
 */
public class RemoteConnectionExceptionHandler implements ProcessExceptionHandler {

	/* (non-Javadoc)
	 * @see co.droidforum.foodx.workers.ProcessExceptionHandler#isHandlerFor(java.lang.Class)
	 */
	public boolean isHandlerFor(Class<? extends Exception> clazz) {
		return clazz.equals(RemoteConnectionServiceException.class);
	}

	/* (non-Javadoc)
	 * @see co.droidforum.foodx.workers.ProcessExceptionHandler#handleException(java.lang.Exception, co.droidforum.foodx.workers.BusinessWorker)
	 */
	public void handleException(Exception e, final BusinessWorker businessWorker) {
		String msgDialog = AplicationContext.getValueStringResource(R.string.msg_error);
		
		DroidAlertDialog.showConfirmCancelDialog(msgDialog, new DroidDialogAction() {
			
			public void onConfirm() {
				businessWorker.runWorker();
			}
			
			public void onCancel() {
				businessWorker.onCancel();
			}
		});
	}
}